package com.ly.dingTalk.service.impl;


import com.ly.dingTalk.bean.oauth.DtOauth2UserInfo;
import com.ly.dingTalk.constant.DtApiPathConstant;
import com.ly.dingTalk.dingcon.DtService;
import com.ly.dingTalk.error.DtErrorException;
import com.ly.dingTalk.service.DtOAuth2Service;

import lombok.RequiredArgsConstructor;

/**
 * oauth2相关接口实现类
 */
@RequiredArgsConstructor
public class DtOAuth2ServiceImpl implements DtOAuth2Service {
    private final DtService mainService;


    @Override
    public DtOauth2UserInfo getUserInfo(String code) throws DtErrorException {
        String responseText = this.mainService.get(String.format(this.mainService.getDtConfigStorage().getApiUrl(DtApiPathConstant.OAuth2.GET_USER_INFO), code), null);

        return DtOauth2UserInfo.fromJson(responseText);
    }

}
